package com.tanhua.app.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.app.interceptor.UserHolder;
import com.tanhua.app.service.SettingsService;
import com.tanhua.domain.db.Settings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    @GetMapping(value = "/users/settings",name = "查询登录用户的陌生人问题和通知喜好")
    public ResponseEntity findUserSetting() throws ClientException {

        return settingsService.findUserSetting();
    }

    @PostMapping(value = "/users/questions",name = "新增/修改登录用户的陌生人问题")
    public ResponseEntity settingUserQuestion(@RequestBody Map param) throws ClientException {
        //获取写入的问题
        String content =(String)param.get("content");
        return settingsService.settingUserQuestion(content);
    }


    @PostMapping(value = "/users/notifications/setting",name = "新增/修改登录用户的通知喜好")
    public ResponseEntity userlikeSetting(@RequestBody Settings settings) throws ClientException {

        return settingsService.userlikeSetting(settings);
    }



    @GetMapping(value = "/users/blacklist",name = "分页查询登录用户的黑名单")
    public ResponseEntity findPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) throws ClientException {

        return settingsService.findPage(page,pagesize);
    }


    @DeleteMapping(value = "/users/blacklist/{uid}",name = "登录用户取消某个黑名单")
    public ResponseEntity deleteById(@PathVariable Long uid) throws ClientException {
        //根据登录用户的id和传递过来的黑名单id做黑名单表的数据删除
        return settingsService.deleteById(UserHolder.getUser().getId(),uid);
    }



}
